// 练习题
; (function () {
    return
    const promise1 = new Promise((resolve, reject) => {
        setTimeout(() => {
            reject()
        })
    })
    const promise2 = promise1.catch(() => {
        return 2
    })

    console.log('promise1',promise1) // 挂起
    console.log('promise2',promise2) // 挂起


    setTimeout(()=>{
        console.log("promise1",promise1) // reject状态 undefind
        console.log("promise2",promise2) // onfull状态 2
    },2000)
})();

; (function () {
    return
    let one = new Promise((resolve, reject) => {
        console.log("学习");
        // resolve('one')
        reject('学习失败了')
    })
    /**
     * 这里two的状态和前面的状态没关系了, 就是返回的状态
     *      
     * */
    let two = one.catch(res => {
        console.log("这里处理了错误")
        // throw new Error('我是错误')
        return new Promise((resolve, reject) => {
            console.log("学习2");
            resolve('学习成功了')
        })
    })
    two.then(res => {
        console.log("这里是成功的回调", res)
    })
})();

; (function () {
    return
    let one = new Promise((resolve, reject) => {
        console.log("学习");
        // resolve('one')
        reject('学习失败了')
    })
    /**
     * 这里因为处理了错误,所以就返回成功的状态
     *      
     * */
    let two = one.catch(res => {
        console.log("这里处理了错误")
        return 11
    })
    two.then(res => {
        console.log("这里是成功的回调", res)
    })
})();



; (function () {
    // 第一个任务没有已决, 第二个任务就还是挂起状态
    return
    let one = new Promise((resolve, reject) => {
        console.log("学习");
        // resolve('one')
        setTimeout(res => {
            resolve('学习成功了')
        }, 1000)

    })
    let two = one.then((res) => {
        console.log(res)
    })

    console.log(two) // 挂起状态 Promise { <pending> }


})();


; (function () {
    return
    let one = new Promise((resolve, reject) => {
        console.log("学习");
        // resolve('one')
        reject('学习失败了')
    })

    let two = one.then((res) => {
        console.log("考试")
    })
    // console.log(two); // 当前的two也是promise对象
    let three = two.then((res) => {
        console.log("出成绩")
    })
})();
